﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace DemoReception
{
    /// <summary>
    /// 酒店住客类
    /// </summary>
    public class CHotelGuest
    {
        /// <summary>
        /// 客人档案号
        /// </summary>
        public string iGstNo { get; set; }
        /// <summary>
        /// 入住状态
        /// </summary>
        public bool isCheckIn { get; set; }

        /// <summary>
        /// 入住标记(已退 E 在住 C 未入住 空白)
        /// </summary>
        public string iCheckFlag { get; set; }

        /// <summary>
        /// 客人名称
        /// </summary>
        public string iGuestName { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        public string iSex { get; set; }

        public Int64 iRoomId;

        /// <summary>
        /// 房号
        /// </summary>
        public string iRoomNo { get; set; }
        /// <summary>
        /// VIP等级
        /// </summary>
        public string iVip { get; set; }
        /// <summary>
        /// 手机
        /// </summary>
        public string iMobile { get; set; }
        /// <summary>
        /// 邮箱地址
        /// </summary>
        public string iEmailAddr { get; set; }
        /// <summary>
        /// 国籍
        /// </summary>
        public string iCountry { get; set; }
        /// <summary>
        /// 城市
        /// </summary>
        public string iCity { get; set; }
        /// <summary>
        /// 语言
        /// </summary>
        public string iLanguage { get; set; }
        /// <summary>
        /// 公司
        /// </summary>
        public string iCompany { get; set; }
        /// <summary>
        /// 客源
        /// </summary>
        public string iCsource { get; set; }
        /// <summary>
        /// 入住时间
        /// </summary>
        public DateTime iCheckInDate { get; set; }
        /// <summary>
        /// 退房时间
        /// </summary>
        public DateTime iCheckOutDate { get; set; }
        /// <summary>
        /// 有效证件号
        /// </summary>
        public string iCardNo { get; set; }
        /// <summary>
        /// 团体名称
        /// </summary>
        public string iTeamName { get; set; }


        public CHotelGuest() { iGstNo = string.Empty; isCheckIn = false; }
        public CHotelGuest(string aGstNo, bool aCheckIn, string aGuestName, string aRoomNo, string aVip, string aMobile, string aEmailAddr,
                            string aCountry, string aCity, string aLanguage, string aCompany, string aCsource, DateTime aCheckInDate, DateTime aCheckOutDate, string aCardNo,
                            string aCheckFlag, string aSex, string aTeamName)
        {
            iGstNo = aGstNo;
            isCheckIn = aCheckIn;
            iGuestName = MakeCleanStr(aGuestName, 50);
            iRoomNo = MakeCleanStr(aRoomNo);
            iVip = MakeCleanStr(aVip, 10);
            iMobile = MakeCleanStr(aMobile, 50);
            iEmailAddr = MakeCleanStr(aEmailAddr);
            iCountry = MakeCleanStr(aCountry, 25);
            iCity = MakeCleanStr(aCity, 25);
            iLanguage = MakeCleanStr(aLanguage, 25);
            iCompany = MakeCleanStr(aCompany, 100);
            iCsource = MakeCleanStr(aCsource, 100);
            iCheckInDate = aCheckInDate;
            iCheckOutDate = aCheckOutDate;
            iCardNo = MakeCleanStr(aCardNo, 100);
            iCheckFlag = aCheckFlag;
            iSex = MakeCleanStr(aSex, 10);
            iTeamName = MakeCleanStr(aTeamName, 100);
        }

        public string MakeCleanStr(string aOriginStr, int aLength = -1)
        {
            if (aOriginStr == null) return string.Empty;
            string CleanString = aOriginStr.Replace("\'", string.Empty);
            CleanString = CleanString.Replace("`", string.Empty);
            if (aLength > 0)
            {
                CleanString = GetStr(CleanString, aLength, "..");
            }
            return CleanString;
        }

        public string GetStr(string aOriginStr, int aLength, string aEndStr)
        {
            string TempStr = aOriginStr.Substring(0, (aOriginStr.Length < aLength + 1) ? aOriginStr.Length : aLength + 1);
            byte[] EncodedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(TempStr);

            StringBuilder CleanStr = new StringBuilder();
            int Count = 0;
            int RealLength = aLength - aEndStr.Length;
            for (int i = 0; i < TempStr.Length; i++)
            {
                if ((int)EncodedBytes[i] == 63) //不能解析的都转为('?')
                    Count += 2;
                else
                    Count += 1;
                if (Count <= RealLength)
                    CleanStr.Append(TempStr.Substring(i, 1));
                else if (Count > aLength)
                    break;
            }

            if (Count <= aLength)
            {
                CleanStr.Clear().Append(TempStr);
                aEndStr = "";
            }
            CleanStr.Append(aEndStr);
            return CleanStr.ToString();
        }
    }


    /// <summary>
    /// 酒店房态
    /// </summary>
    public class CHotelRoom
    {
        public Int64 iRoomId;
        /// <summary>
        /// 房间号
        /// </summary>
        public string iRoomNo;

        /// <summary>
        /// 房型
        /// </summary>
        public string iTypeName;

        /// <summary>
        /// 有住客
        /// </summary>
        public string iStatusCode;

        public CHotelRoom() { }
        public CHotelRoom(Int64 aRoomId,string aRoomNo, string aTypeName, bool aHasGuest, int aIsDirty, bool aIsAbnormal)
        {
            iRoomId = aRoomId;
            iRoomNo = aRoomNo;
            iTypeName = aTypeName;
            SetStatusCode(aHasGuest, aIsDirty, aIsAbnormal);
        }

        public void SetStatusCode(bool aHasGuest, int aIsDirty, bool aIsAbnormal)
        {
            iStatusCode = CHotelRoomStatusCode.KEmpDir;
            if (aIsAbnormal)
            {
                switch (aIsDirty)
                {
                    case CHotelRoomCleanStatus.KClean: iStatusCode = CHotelRoomStatusCode.KOOCln; break;
                    case CHotelRoomCleanStatus.KDirty: iStatusCode = CHotelRoomStatusCode.KOODir; break;
                    case CHotelRoomCleanStatus.KUnkown: iStatusCode = CHotelRoomStatusCode.KOOUnk; break;
                }
            }
            else
            {
                if (aHasGuest)
                {
                    if (aIsDirty == CHotelRoomCleanStatus.KClean) iStatusCode = CHotelRoomStatusCode.KOccCln;
                    else iStatusCode = CHotelRoomStatusCode.KOccDir;
                }
                else
                {
                    if (aIsDirty == CHotelRoomCleanStatus.KClean) iStatusCode = CHotelRoomStatusCode.KEmpCln;
                    else iStatusCode = CHotelRoomStatusCode.KEmpDir;
                }
            }
        }
    }

    public class CHotelCheckFlag
    {
        public const string KCheckIn = "C";
        public const string KCheckOut = "E";
        public const string KEmpty = "";
        public const string KCancel = "X";
    }

    public class CHotelRoomCleanStatus
    {
        public const int KClean = 0;
        public const int KDirty = 1;
        public const int KUnkown = 2;
    }

    public class CHotelRoomStatusCode
    {
        public const string KOccCln = "OC";
        public const string KOccDir = "OD";
        public const string KEmpCln = "VC";
        public const string KEmpDir = "VD";
        public const string KOOCln = "OSC";
        public const string KOODir = "OSD";
        /// <summary>未知锁房时候是干净还是脏</summary>
        public const string KOOUnk = "OO";
        /// <summary>暂停服务(未使用)</summary>
        public const string KOutSer = "OS";
    }

    [DataContract]
    public class CGetTodayGuestResult : CNodeJsResult
    {
        [DataMember]
        public List<EmRoomGuest> iGuestList;
    }

    [DataContract]
    public class CGetGuestListResult : CNodeJsResult
    {
        [DataMember]
        public List<EmGuestLite> iGuest;
    }

    [DataContract]
    public class CGetTeamNameResult : CNodeJsResult
    {
        [DataMember]
        public List<string> iTeam;
    }

    [DataContract]
    public class CGetNeewGstNameResult : CNodeJsResult
    {
        [DataMember]
        public string iName;
    }

    [DataContract]
    public class CGetGuestInfoResult : CNodeJsResult
    {
        [DataMember]
        public EmGuestInfo iGuest;
    }

    [DataContract]
    public class EmGuestLite
    {
        [DataMember]
        public string iGuestNo;
        [DataMember]
        public string iGuestName;
        [DataMember]
        public string iSex;
        [DataMember]
        public string iVip;
    }

    [DataContract]
    public class EmGuestInfo : EmGuestLite
    {
        [DataMember]
        public string iCity;
        [DataMember]
        public string iEmail;
        [DataMember]
        public string iMobile;
        [DataMember]
        public string iLang;
        [DataMember]
        public string iCardNo;
        [DataMember]
        public string iNation;
    }

    [DataContract]
    public class EmRoomGuest: EmGuestLite
    {
        [DataMember]
        public Int64 iRoomId;
        [DataMember]
        public string iRoomName;
        [DataMember]
        public string iCheckFlag;
        [DataMember]
        public long iCheckOutTime;
        [DataMember]
        public long iCheckInTime;
        [DataMember]
        public string iTeamName;
        [DataMember]
        public string iCompany;
    }

    
}